import { defineStore } from "pinia"
import * as THREE from 'three'
import { GeometryShape } from "@/graph/3d/config/shapes"

interface SceneState {
  scene: THREE.Scene | null
  elements: GeometryShape[]
}

export const useSceneStore = defineStore('scene', {
  state: (): SceneState => ({
    scene: null,
    elements: []
  }),
  getters: {
    getScene: (state) => state.scene
  },
  actions: {
    setScene(state: THREE.Scene) {
      this.scene = state
    },
    addElement(state: GeometryShape | GeometryShape[]) {
      const elements = Array.isArray(state) ? state : [state]
      this.elements.push(...elements)
    },
    removeElement(state: string | string[]) {
      const ids = Array.isArray(state) ? state : [state]
      this.elements = this.elements.filter(item => !ids.includes(item.id))
    }
  }
})

